home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / AIAT / Examples / Sources / DemoAccessor.cpp < prev    next >
Encoding:
Text File  |  1998-04-16  |  17.5 KB  |  665 lines  |  [TEXT/CWIE]

  1. /// DemoAccessor.cpp
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. #include "DemoAccessor.h"
  6.  
  7. #ifdef DEBUG_NEW
  8. #include <DebugNew.h>
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #if __profile__
  15. #include <profiler.h>
  16. #endif
  17.  
  18. void PrintDocName(IADoc* doc);
  19. void PrintDocName(IADoc* doc) {
  20.     uint32 docNameLength;
  21.     char* docName = (char*)doc->GetName(&docNameLength);
  22. //    IAAssert(strlen(docName) == docNameLength);
  23.     IAAssertion(strlen(docName) == docNameLength, "mismatch document names", IAAssertionFailure);
  24.     printf("%s", docName);
  25.     IAFreeArray(docName);
  26. }
  27.  
  28. void DemoAccessor::Initialize() {
  29.     time_t initStartTime = time(NULL);
  30.     DEMOACCESSORCLASS::Initialize();
  31.     time_t initTime = time(NULL) - initStartTime;
  32.     struct tm* timeStruct = localtime(&initTime);
  33.     char buffer[80];
  34.     strftime(buffer, 80, "accessor initialization: %H hours, %M minutes and %S seconds.\n", timeStruct);
  35.     printf(buffer);
  36. }
  37.  
  38. bool    DemoAccessor::IsHit(IAIndex* index, const IADoc* doc) {
  39.     #pragma unused(index)
  40.     bool result = true;
  41.     if (firstChar) {
  42.       uint32 docNameLength;
  43.       char* docName = (char*)doc->GetName(&docNameLength);
  44.       if (!docNameLength) {
  45.         result = false;
  46.       } else if (docName[0] != firstChar) {
  47.         result = false;
  48.       }
  49.       IAFreeArray(docName);
  50.     }
  51.     return result;
  52. }
  53.  
  54. //// Calling the IAAccessor
  55.  
  56. bool DemoRankedProgress(const RankedProgress* progress, void* data);
  57. bool DemoRankedProgress(const RankedProgress* progress, void* data) {
  58.     #pragma unused (data)
  59.     printf("searching: %4.1f ", progress->GetPercent());
  60.     if (progress->GetTerm()) {
  61.       printf("%s", (char*)progress->GetTerm()->GetData());
  62.     }
  63.     if (progress->GetDocument()) {
  64.       PrintDocName(progress->GetDocument());
  65.     }
  66.     printf("\n");
  67.     return false;
  68. }
  69.  
  70. const MaxResultCount = 15;
  71. const uint32 kMaxDocuments = 10;
  72.  
  73. void DemoRankedSearchInternal (DemoAccessor* accessor, char* query, IADoc** feedback, uint32 nrq);
  74. void DemoRankedSearchInternal (DemoAccessor* accessor, char* query, IADoc** feedback, uint32 nrq) {
  75.     RankedQueryDoc rqd1[kMaxDocuments];
  76.     if (nrq > kMaxDocuments) nrq = kMaxDocuments;
  77.     printf("Query: %s\n", query);                            // display query
  78.     for (int i = 0; i < nrq; i ++) {
  79.     printf("Feedback: ");
  80.       PrintDocName(feedback[i]);
  81.       printf("\n");
  82.     }
  83.  
  84.     time_t start = time(NULL);
  85.     
  86.  
  87.     RankedHit* results[MaxResultCount];                    // allocate array for results
  88.     // RankedQueryDoc rqd(feedback, TermIndex::IANarrow(accessor->indices[0]));
  89.     
  90.     for (int i = 0; i <nrq; i++) {
  91.         rqd1[i].doc = feedback[i];
  92.         rqd1[i].index =  TermIndex::IANarrow(accessor->GetIndices()[0]);
  93.     }
  94.     // execute query
  95.     uint32 resultCount = accessor->RankedSearch((byte*)query, strlen(query),    // query string
  96.                                                 rqd1, nrq,            // feedback doc
  97.                                                 results, MaxResultCount, 4,        // result array
  98.                                                 &DemoRankedProgress, 30, NULL);    // progress args
  99.  
  100.     time_t duration = time(NULL) - start;
  101.     struct tm* timeStruct = localtime(&duration);
  102.     char buffer[80];
  103.     strftime(buffer, 80, "search time: %H hours, %M minutes and %S seconds.\n", timeStruct);
  104.     printf(buffer);
  105.  
  106.     printf("%lu hits\n", resultCount);                    // display results
  107.     for (uint32 i = 0; i < resultCount; i++) {
  108.       RankedHit* hit = results[i];
  109.       printf("%5.2f : ", hit->GetScore());
  110.       PrintDocName(hit->GetDocument());
  111.       printf(" [");
  112.       for (uint32 j = 0; j < hit->GetMatchingTermsLen(); j++)
  113.         printf(" %s", hit->GetMatchingTerms()[j]->GetData());
  114.       printf("]\n");
  115.       delete hit;
  116.     }
  117. }
  118.  
  119. void DemoRankedSearch (char* query, IADoc* feedback = NULL, char firstChar = NULL, bool update = false);
  120. void DemoRankedSearch (char* query, IADoc* feedback, char firstChar, bool update) {
  121.     // make a storage
  122.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  123.     IADeleteOnUnwind delStorage(storage);
  124.     if (update) {
  125.         storage->Open(true); // just to be on the safeside of handling changes in index
  126.     }
  127.     else {
  128.         storage->Open(false);
  129.     }
  130.     // make an index in this storage
  131.     DemoIndex index(storage);
  132.     index.Open();
  133. /*
  134.     // make a second storage
  135.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  136.     IADeleteOnUnwind delStorage2(storage2);
  137.     storage2->Open(false);
  138.     // make a second index in this storage
  139.     DemoIndex index2(storage2);
  140.     index2.Open();
  141. */
  142.     const uint32 nIndices = 1;
  143.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  144.     indices[0] = &index;
  145. /*
  146.     indices[1] = &index2;
  147. */
  148.     DemoAccessor accessor(indices, nIndices);        // make appropriate accessor
  149.     accessor.firstChar = firstChar;
  150. time_t start = time(NULL);
  151.     if (!update) {
  152.         accessor.Initialize();
  153.     }
  154.     else {
  155.         accessor.Update();
  156.     }
  157. time_t duration = time(NULL) - start;
  158. struct tm* timeStruct = localtime(&duration);
  159. char buffer[80];
  160. strftime(buffer, 80, "accessor update/initialization time: %H hours, %M minutes and %S seconds.\n", timeStruct);
  161. printf(buffer);
  162.  
  163.     DemoRankedSearchInternal(&accessor, query, &feedback, 0);
  164. }
  165.  
  166. void DemoBooleanRankedSearchInternal (DemoAccessor* accessor, char* query);
  167. void DemoBooleanRankedSearchInternal (DemoAccessor* accessor, char* query) {
  168.     RankedQueryDoc rqd1[kMaxDocuments];
  169.  
  170.     printf("Query: %s\n", query);                            // display query
  171.  
  172.     time_t start = time(NULL);
  173.     
  174.  
  175.     RankedHit* results[MaxResultCount];                    // allocate array for results
  176.     uint32 resultCount = 0;
  177.     // RankedQueryDoc rqd(feedback, TermIndex::IANarrow(accessor->indices[0]));
  178. #ifdef DEMOINDEXISINVERTED
  179.     
  180.     // execute query
  181. ((InvertedAccessor*)accessor)->SetBooleanAndOperator('+');
  182. ((InvertedAccessor*)accessor)->SetBooleanOrOperator('|');
  183. ((InvertedAccessor*)accessor)->SetBooleanNotOperator('-');
  184. ((InvertedAccessor*)accessor)->SetBooleanLeftFence('[');
  185. ((InvertedAccessor*)accessor)->SetBooleanRightFence(']');
  186.  
  187.     resultCount = ((InvertedAccessor*)accessor)->RankedSearchBoolean((byte*)query, strlen(query),    // query string
  188.                                                 results, MaxResultCount,         // result array
  189.                                                 &DemoRankedProgress, 30, NULL);    // progress args
  190. #endif
  191.  
  192.     time_t duration = time(NULL) - start;
  193.     struct tm* timeStruct = localtime(&duration);
  194.     char buffer[80];
  195.     strftime(buffer, 80, "search time: %H hours, %M minutes and %S seconds.\n", timeStruct);
  196.     printf(buffer);
  197.  
  198.     printf("%lu hits\n", resultCount);                    // display results
  199.     for (uint32 i = 0; i < resultCount; i++) {
  200.       RankedHit* hit = results[i];
  201.       printf("%5.2f : ", hit->GetScore());
  202.       PrintDocName(hit->GetDocument());
  203.        printf("\n");
  204.       delete hit;
  205.     }
  206. }
  207.  
  208. void DemoBooleanRankedSearch (char* query,  char firstChar = NULL);
  209. void DemoBooleanRankedSearch (char* query,  char firstChar) {
  210.     // make a storage
  211.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  212.     IADeleteOnUnwind delStorage(storage);
  213.     storage->Open(false);
  214.     // make an index in this storage
  215.     DemoIndex index(storage);
  216.     index.Open();
  217. /*
  218.     // make a second storage
  219.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  220.     IADeleteOnUnwind delStorage2(storage2);
  221.     storage2->Open(false);
  222.     // make a second index in this storage
  223.     DemoIndex index2(storage2);
  224.     index2.Open();
  225. */
  226.     const uint32 nIndices = 1;
  227.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  228.     indices[0] = &index;
  229. /*
  230.     indices[1] = &index2;
  231. */
  232.     DemoAccessor accessor(indices, nIndices);        // make appropriate accessor
  233.     accessor.firstChar = firstChar;
  234.     accessor.Initialize();
  235.  
  236.     DemoBooleanRankedSearchInternal(&accessor, query);
  237. }
  238.  
  239. void DemoFeedback (char firstChar = NULL);
  240. void DemoFeedback (char firstChar) {
  241.     // make a storage
  242.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  243.     IADeleteOnUnwind delStorage(storage);
  244.     storage->Open(false);
  245.     // make an index in this storage
  246.     DemoIndex index(storage);
  247.     index.Open();
  248. /*
  249.     // make a second storage
  250.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  251.     IADeleteOnUnwind delStorage2(storage2);
  252.     storage2->Open(false);
  253.     // make a second index in this storage
  254.     DemoIndex index2(storage2);
  255.     index2.Open();
  256. */
  257.     const uint32 nIndices = 1;
  258.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  259.     indices[0] = &index;
  260. /*
  261.     indices[1] = &index2;
  262. */
  263.  
  264.     DemoAccessor accessor(indices, nIndices);        // make appropriate accessor
  265.     accessor.firstChar = firstChar;
  266.     accessor.Initialize();
  267.  
  268.     DocID maxID = index.GetMaxDocID();
  269.     if (maxID > 1) {
  270.       IADoc* doc = index.GetIDDoc(maxID / 2);
  271.       IADeleteOnUnwind delDoc(doc);
  272.       printf ("FIND DOCUMENTS LIKE >>>>>>>>  ");
  273.       PrintDocName(doc);
  274.       printf ("\n");
  275.       DemoRankedSearchInternal(&accessor, "", &doc, 1);
  276.     }
  277. }
  278.  
  279.  
  280. void DemoFeedbacks(char firstChar = NULL);
  281. void DemoFeedbacks(char firstChar) {
  282.     // make a storage
  283.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  284.     IADeleteOnUnwind delStorage(storage);
  285.     storage->Open(false);
  286.     // make an index in this storage
  287.     DemoIndex index(storage);
  288.     index.Open();
  289.  
  290.     const uint32 nIndices = 1;
  291.     const uint32 ndocs = 3;
  292.     const uint32 loopControl = 2;
  293.     HFSDoc* fbdocs[kMaxDocuments];
  294.     DEMOACCESSORINDEXCLASS* indices[nIndices];            // make indices
  295.     indices[0] = &index;
  296.  
  297.     DemoAccessor accessor(indices, nIndices);        // make appropriate accessor
  298.     accessor.firstChar = firstChar;
  299.     accessor.Initialize();
  300.  
  301.     IAOrderedStorableIterator* docs = index.GetDocInfoIterator();
  302.     IADeleteOnUnwind delDocs(docs);
  303.     
  304. uint32 j = 0;
  305.     for (DocInfo* di = (DocInfo*)docs->Next(); di; di = (DocInfo*)docs->Next()) {
  306.       IADeleteOnUnwind delDi(di);
  307.         for (int i = 0; i < ndocs; i++) {
  308.             fbdocs[i] = (HFSDoc*) di->GetDocument();
  309.             di = (DocInfo*)docs->Next();
  310.         }
  311.       DemoRankedSearchInternal(&accessor, "", (IADoc**)fbdocs, ndocs);
  312.         if (++j > loopControl) break;
  313.     }
  314. }
  315.  
  316. void DemoGetDocTopic();
  317. void DemoGetDocTopic() {
  318.     // make a storage
  319.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  320.     IADeleteOnUnwind delStorage(storage);
  321.     storage->Open(false);
  322.     // make an index in this storage
  323.     DemoIndex index(storage);
  324.     index.Open();
  325.  
  326. /*
  327.     // make a second storage
  328.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  329.     IADeleteOnUnwind delStorage2(storage2);
  330.     storage2->Open(false);
  331.     // make a second index in this storage
  332.     DemoIndex index2(storage2);
  333.     index2.Open();
  334. */
  335.     const uint32 nIndices = 1;
  336.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  337.     indices[0] = &index;
  338. /*
  339.     indices[1] = &index2;
  340. */
  341.     DemoAccessor accessor(indices, nIndices);                // make appropriate accessor
  342.     accessor.Initialize();
  343.  
  344.     IATerm* results[MaxResultCount];                        // allocate array for results
  345.  
  346.     DocID maxID = index.GetMaxDocID();
  347.     if (maxID > 1) {
  348.       IADoc* doc = index.GetIDDoc(maxID / 2);
  349.       IADeleteOnUnwind delDoc(doc);
  350.       printf("Doc: ");
  351.       PrintDocName(doc);
  352.       printf("\n");
  353.  
  354.       time_t start = ::time(NULL);
  355.  
  356.       RankedQueryDoc rqd(doc, &index);
  357.       uint32 resultCount = accessor.GetDocTopic(    &rqd, results, MaxResultCount,
  358.                                                     &DemoRankedProgress, 30, NULL);
  359.       time_t duration = ::time(NULL) - start;
  360.       struct tm* timeStruct = localtime(&duration);
  361.       char buffer[80];
  362.       strftime(buffer, 80, "time: %H hours, %M minutes and %S seconds.\n", timeStruct);
  363.       printf(buffer);
  364.  
  365.       printf("terms:");
  366.       for (uint32 i = 0; i < resultCount; i++) {
  367.         IATerm* term = results[i];
  368.         printf(" %s", term->GetData());
  369.         delete term;
  370.       }
  371.       printf("\n");
  372.     }
  373. }
  374.  
  375. void DemoStoreInits (bool force = false);
  376. void DemoStoreInits (bool force) {
  377.     // make a storage
  378.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  379.     IADeleteOnUnwind delStorage(storage);
  380.     storage->Open(true);                            // note: opened writably
  381.     // make an index in this storage
  382.     DemoIndex index(storage);
  383.     index.Open();
  384. /*
  385.     // make a second storage
  386.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  387.     IADeleteOnUnwind delStorage2(storage2);
  388.     storage2->Open(false);
  389.     // make a second index in this storage
  390.     DemoIndex index2(storage2);
  391.     index2.Open();
  392. */
  393.     const uint32 nIndices = 1;
  394.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  395.     indices[0] = &index;
  396. /*
  397.     indices[1] = &index2;
  398. */
  399.     DemoAccessor accessor(indices, nIndices);
  400.  
  401.     if (force || !accessor.IsInitializationValid()) {
  402.       printf("Computing accessor initializations.\n");
  403.       time_t initStartTime = time(NULL);
  404.  
  405.       accessor.StoreInitialization();                // store initialization
  406.       storage->Commit();                            // save changes
  407.  
  408.       time_t initTime = time(NULL) - initStartTime;
  409.       struct tm* timeStruct = localtime(&initTime);
  410.       char buffer[80];
  411.       strftime(buffer, 80, "store inits: %H hours, %M minutes and %S seconds.\n", timeStruct);
  412.       printf(buffer);
  413.     } else {
  414.       printf("Initialization is already up to date.\n");
  415.     }
  416.  
  417. }
  418.  
  419. void DemoDelete ();
  420. void DemoDelete () {
  421.     // make a storage
  422.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  423.     IADeleteOnUnwind delStorage(storage);
  424.     storage->Open(true);
  425.     // make an index in this storage
  426.     DemoIndex index(storage);
  427.     index.Open();
  428.  
  429.     DocID maxID = index.GetMaxDocID();
  430.     if (maxID > 1) {
  431.       IADoc* doc = index.GetIDDoc(maxID / 2);
  432.       IADeleteOnUnwind delDoc(doc);
  433.       index.DeleteDoc(doc);
  434.       index.Flush();
  435.       storage->Commit();            // commit the changes
  436.     }
  437. }
  438.  
  439. void DemoDeleteAll ();
  440. void DemoDeleteAll () {
  441.     // make a storage
  442.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  443.     IADeleteOnUnwind delStorage(storage);
  444.     storage->Open(true);
  445.     // make an index in this storage
  446.     DemoIndex index(storage);
  447.     index.Open();
  448.  
  449.     for (DocID id = 1; id < index.GetMaxDocID(); id++) {
  450.       IADoc* doc = index.GetIDDoc(id);
  451.       IADeleteOnUnwind delDoc(doc);
  452.       index.DeleteDoc(doc);
  453.     }
  454.     index.Flush();
  455.     storage->Commit();                // commit the changes
  456. }
  457.  
  458.  
  459. void DemoCompact ();
  460. void DemoCompact () {
  461.     // make a storage
  462.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  463.     IADeleteOnUnwind delStorage(storage);
  464.     storage->Open(true);
  465.     // make an index in this storage
  466.     DemoIndex index(storage);
  467.     index.Open();
  468.  
  469.     printf("compacting...\n");
  470.     index.Compact();
  471. }
  472.  
  473.  
  474. void DemoRelatedTerms(char* query);
  475. void DemoRelatedTerms(char* query) {
  476.     printf (">>>>>>> The Related Terms %s\n", query);
  477.     // make a storage
  478.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  479.     IADeleteOnUnwind delStorage(storage);
  480.     storage->Open(false);
  481.     // make an index in this storage
  482.     DemoIndex index(storage);
  483.     index.Open();
  484. /*
  485.     // make a second storage
  486.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  487.     IADeleteOnUnwind delStorage2(storage2);
  488.     storage2->Open(false);
  489.     // make a second index in this storage
  490.     DemoIndex index2(storage2);
  491.     index2.Open();
  492. */
  493.     const uint32 nIndices = 1;
  494.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  495.     indices[0] = &index;
  496. /*
  497.     indices[1] = &index2;
  498. */
  499.     DemoAccessor accessor(indices, nIndices);                // make appropriate accessor
  500.     accessor.firstChar = '\0';
  501.     accessor.Initialize();
  502.  
  503.     IATerm* termResults[MaxResultCount];                        // allocate array for results
  504.     
  505.     uint32 resultCount = accessor.GetTermsRelated((byte*)query, strlen(query),    // query string
  506.                                                 termResults, MaxResultCount,        // result array
  507.                                                 &DemoRankedProgress, 30, NULL);    // progress args
  508.  
  509.       printf("related terms:");
  510.       for (uint32 i = 0; i < resultCount; i++) {
  511.         IATerm* term = termResults[i];
  512.         printf(" %s", term->GetData());
  513.         delete term;
  514.       }
  515.       printf("\n");
  516.       printf ("<<<<<<< \n");
  517.  
  518. }
  519.  
  520. #if 0
  521. void DemoOpen();
  522. void DemoOpen () {
  523.     // make a storage
  524.     StringPtr name = "\ptest.index";
  525.     short vRefNum = 0;
  526.     long dirID = 0;
  527.  
  528.     IAStorage * aStorage = MakeHFSStorage(vRefNum, dirID, name);
  529.     IADeleteOnUnwind delInxStorage(aStorage);
  530.     aStorage->Open(true);                            
  531.  
  532.     HFSCorpus* anHFSCorpus = new HFSCorpus(HFSCorpusType);
  533.     InVecIndex anInVecIndex(aStorage, anHFSCorpus, new SimpleAnalysis());
  534.  
  535.     anInVecIndex.Open();
  536. }
  537. #endif
  538.  
  539. void DemoUpdateInits ();
  540. void DemoUpdateInits () {
  541.     // make a storage
  542.     IAStorage* storage = DEMOSTORAGE(DEMOINDEXFILENAME);
  543.     IADeleteOnUnwind delStorage(storage);
  544.     storage->Open(true);                            // note: opened writably
  545.     // make an index in this storage
  546.     DemoIndex index(storage);
  547.     index.Open();
  548. /*
  549.     // make a second storage
  550.     IAStorage* storage2 = DEMOSTORAGE("\pp2.index");
  551.     IADeleteOnUnwind delStorage2(storage2);
  552.     storage2->Open(false);
  553.     // make a second index in this storage
  554.     DemoIndex index2(storage2);
  555.     index2.Open();
  556. */
  557.     const uint32 nIndices = 1;
  558.     DEMOACCESSORINDEXCLASS* indices[nIndices];        // make indices
  559.     indices[0] = &index;
  560. /*
  561.     indices[1] = &index2;
  562. */
  563.     DemoAccessor accessor(indices, nIndices);
  564.     accessor.Update();
  565.     IATry {
  566.         accessor.Store();                
  567.         storage->Commit();                            
  568.     }
  569.     IACatch (const IAException& exception) {
  570.         printf("got exception can not save an updated accessor\n");
  571.     }
  572.  
  573. }
  574.  
  575. char* GetQueryText(const char* promp);
  576. char* GetQueryText(const char* promp)
  577. {
  578.  
  579.   char lq[1024];
  580.   int i = 0;
  581.   printf ("%s >> ", promp);
  582.   while (!feof(stdin)) {
  583.     char cc = fgetc(stdin);
  584.     if (cc == '\n' || i == 1023) break;
  585.     lq[i++] = cc;
  586.   }
  587.   lq[i] = '\0';
  588.   if (i == 0) return NULL;
  589.   char* query = (char*)IAMallocArraySized(byte, i + 1);
  590.   if (query != NULL) {
  591.     memcpy(query, lq, i);
  592.     query[i] = '\0';
  593.   }
  594.   return query;
  595. }
  596.  
  597. /// the main procedure
  598.  
  599. void main() {
  600.  
  601. #if __profile__
  602. #ifdef powerc
  603.     ProfilerInit(collectDetailed, PPCTimeBase, 1500, 50);
  604. #else
  605.     ProfilerInit(collectSummary, microsecondsTimeBase, 1500, 50);
  606. #endif    
  607. #endif
  608.  
  609.     IATry {
  610.         DemoStoreInits(true);   // for profile
  611. //        DemoUpdateInits ();
  612.  
  613.         bool notDone = true;
  614.         while (notDone) {        
  615.           char* query = GetQueryText("Enter Query");
  616.           if (query != NULL) {
  617.             if (strpbrk(query, "[|+-]") == NULL) {
  618.               DemoRankedSearch(query, NULL, NULL, false);
  619.             }
  620.             else {
  621. #ifdef DEMOINDEXISINVERTED
  622.               DemoBooleanRankedSearch(query, NULL);
  623. #else
  624.               printf ("Need Inverted Index Type for Boolean Queries\n");
  625. #endif
  626.             }
  627.             IAFreeArraySized (query, byte, strlen(query) + 1);
  628.           }
  629.           else {
  630.             notDone = false;
  631.           }
  632.         }
  633.  
  634.         char* termQuery = GetQueryText("Enter Term for Related Terms");
  635.         if (termQuery != NULL) {
  636.           DemoRelatedTerms (termQuery);
  637.           IAFreeArraySized (termQuery, byte, strlen(termQuery) + 1);
  638.         }
  639.                   
  640.         DemoGetDocTopic();
  641.         DemoFeedback();
  642.  
  643. //        DemoDeleteAll();
  644. //        DemoDelete();
  645. //        DemoCompact();
  646.  
  647.     }
  648.     IACatch (const IAException& exception) {
  649.         printf("Caught exception: %s\n", exception.What());
  650.     }
  651.  
  652. #if __profile__
  653.     ProfilerDump("\pDemoAccessor.prof");
  654.     ProfilerTerm();
  655. #endif
  656.  
  657. #ifdef IADEBUG
  658.     IAReportMemoryUsage();
  659. #endif
  660.  
  661. #ifdef DEBUG_NEW
  662.     DebugNewReportLeaks();
  663. #endif
  664. }
  665.